package com.wyg.client;

import com.wyg.service.BookService;
import com.wyg.service.UserService;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @description:
 * @author: WYG
 * @time: 2020/10/27 9:03
 */

public class MyProxy {

    public static void main(String[] args) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
        UserService instance = (UserService) Proxy.newProxyInstance(MyProxy.class.getClassLoader(), new Class[]{UserService.class}, new InvocationHandler() {
            @Override
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                System.out.println(method.getDeclaringClass().getName());
                System.out.println(method.getName());
                System.out.println(args[0]);
                return null;
            }
        });
        // System.out.println(instance.findUserById(1));
        /*Class<?> proxyClass = Proxy.getProxyClass(MyProxy.class.getClassLoader(), UserService.class);
        System.out.println(proxyClass);
        UserService instance = (UserService) proxyClass.getConstructor(InvocationHandler.class).newInstance(new InvocationHandler() {
            @Override
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                return method.getName() == "deleteUser" ? 0 : 1;
            }
        });
        System.out.println(instance.deleteUser(1));*/
    }

}
